//
//  ViewController.m
//  demo_soap
//
//  Created by zc on 13-9-26.
//  Copyright (c) 2013年 zc. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property  (strong,nonatomic)NSString *xmlReqStr;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
//    NSString *requestFilePath = [[NSBundle mainBundle]pathForResource:@"soapXML" ofType:@"xml"];
//    NSLog(@"path %@",requestFilePath);
    _xmlReqStr = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
    "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                  "<soap:Body>\n"
                  " <getDomesticAirlinesTime xmlns=\"http://WebXml.com.cn/\">\n"
                  "<startCity>%@</startCity>\n"
                  "<lastCity>%@</lastCity>\n"
                  "<theDate>%@</theDate>\n"
                  "<userID>%@</userID>\n"
                  "</getDomesticAirlinesTime>\n"
                  "</soap:Body>\n"
                  "</soap:Envelope>\n",@"重庆",@"",@"",@""
                  ];
    
    NSLog(@"%@\n\n",_xmlReqStr);
    
    NSString *requestMsg = [[NSString alloc]initWithFormat:@"%@",_xmlReqStr];
    
//    NSLog(@" Msg ----> %@",requestMsg);
    
    NSURL *webServiceUrl = [NSURL URLWithString:@"http://www.WebXml.com.cn//webservices/DomesticAirline.asmx"];
    NSMutableURLRequest *Webrequest = [NSMutableURLRequest requestWithURL:webServiceUrl];
    
//    [Webrequest addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [Webrequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [Webrequest addValue: @"http://WebXml.com.cn/getDomesticAirlinesTime" forHTTPHeaderField:@"SOAPAction"];
    
//    [Webrequest addValue:@"Content-Length" forHTTPHeaderField:[NSString stringWithFormat:@"%d",[requestMsg length]]];
    [Webrequest addValue:[NSString stringWithFormat:@"%d",[requestMsg length]] forHTTPHeaderField:@"Content-Length"];
    [Webrequest setHTTPMethod:@"POST"];
    
    [Webrequest setHTTPBody:[_xmlReqStr dataUsingEncoding:NSUTF8StringEncoding]];
    
    
    
    NSOperationQueue *queue = [[NSOperationQueue alloc]init];
    [NSURLConnection sendAsynchronousRequest:Webrequest queue:queue completionHandler:^(NSURLResponse *urlResponse,NSData * responseData,NSError *error){
        if (error) {
            NSLog(@"errorooooooooo");
            return ;
        }
        NSString *str = [[NSString alloc]initWithBytes:[responseData bytes] length:[responseData length] encoding:NSUTF8StringEncoding];
//        NSString *response = [[NSString  alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
//        NSLog(@"response Data  ----->%@",responseData);
        NSLog(@" str ----%@",str);
    }];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
